<template>
	<div>
		<navigation-bar>
			<div class="searchContent">
				<el-input
					v-model="name"
					placeholder="请输入名称"
					size="mini"
					style="width: 150px; margin-right: 10px"
				></el-input>
				<custom-button
					type="search"
					style="margin-right: 10px"
					@searchClick="searchClick"
				></custom-button>
				<custom-button
					type="reset"
					style="margin-right: 10px"
					@resetClick="resetClick"
				></custom-button>
			</div>
		</navigation-bar>
		<el-row>
			<el-col :span="5">
				<div style="width: 100%">
					<user-list @handleSelectionChange="handleSelectionChange" ref="userList"  @addClick="addClick"></user-list>
				</div>
			</el-col>
			<el-col :span="19">
				<table-index
					:dataSource="dataSource"
					:tableColumns="tableColumns"
					:btnList="btnList"
					:pageSize="pageSize"
					:pageCount="pageCount"
					:pageNo="pageNo"
					@pageChange="pageChange"
					@editRow="editRow"
					@viewRow="viewRow"
					@deleteRow="deleteRow"
				></table-index>
			</el-col>
		</el-row>
		<div v-if="dialogShow">
			<custom-dialog
				:title="dialogTitle"
				size="large"
				@dialogClose="dialogClose"
			>
				<form-index :formConfig="formConfig" @submit="submit" :type="type">
					<!--  <div>这里还可以插入其它内容进行拓展</div> -->
				</form-index>
			</custom-dialog>
		</div>
	</div>
</template>

<script>
	import { testPicturesOfSubjectsForm } from "@/assets/form/managementCenter/subjectManagement/otherManagement/testPicturesOfSubjectsForm"
	import customDialog from "@/components/customComponents/customDialog"
	import customButton from "@/components/customComponents/customForm/customButton"
	import formIndex from "@/components/customComponents/customForm/formIndex"
	import tableIndex from "@/components/customComponents/customeTable/tableIndex"
	import navigationBar from "@/components/customComponents/managementCenter/navigationBar"
	import userList from "@/components/customComponents/managementCenter/userList"
	import { AjaxCommon } from "@/libs/apiCommon"
	import { PopupCommon } from "@/libs/popupCommon"
	import { SessionCommon } from "@/libs/sessionCommon"
	export default {
		components: {
			navigationBar,
			customButton,
			tableIndex,
			customDialog,
			formIndex,
			userList,
		},
		data() {
			return {
				leftSelectIds: [],
				leftDataSource: [],
				leftTableColumns: [
					{
						prop: "examineeName",
						label: "受试者姓名",
					},
				],
				name: "",
				signPrefix: "",
				// table 相关参数  begin
				dataSource: [],
				tableColumns: [
					{
						prop: "filterNo",
						label: "筛选号",
					},
					{
						prop: "filterNo",
						label: "随机号",
					},
					{
						prop: "filterNo",
						label: "入组顺序号",
						width: 120,
					},
					{
						prop: "filterNo",
						label: "周期号",
					},
					{
						prop: "examineeName",
						label: "受试者姓名",
						width: 120,
					},
					{
						prop: "sex",
						label: "性别",
					},
					{
						prop: "height",
						label: "给药顺序号",
						width: 120,
					},
					{
						prop: "weight",
						label: "图片描述",
						width: 120,
					},
					{
						prop: "bmi",
						label: "记录人",
					},
					{
						prop: "createTime",
						label: "记录时间",
					},
					{
						prop: "createTime",
						label: "备注",
					},
				],
				btnList: ["edit", "view", "delete"],
				pageSize: 20,
				pageCount: 100,
				pageNo: 1,
				// table 相关参数  end

				// 弹窗是否显示
				dialogShow: false,
				// 弹窗标题 (新增修改不同)
				dialogTitle: "",

				// form的配置信息
				formConfig: testPicturesOfSubjectsForm,
				type: "add",
			}
		},
		methods: {
			dialogClose() {
				this.dialogShow = false
			this.$refs.userList.handleClearTableRow()
			},
			searchClick() {
				this.pageNo = 1
				this.initPage()
			},
			resetClick() {
				this.name = ""
				this.signPrefix = ""
			},
			// 分页点击事件
			pageChange(p) {
				this.pageNo = p
				this.initPage()
			},
			editRow(d) {
				this.type = "edit"
				let formConfigItem = this.formConfig
				formConfigItem.map((t) => {
					Object.keys(t).map((res) => {
						if (res == "fieldName") {
							t.filedValue = d.data[t[res]]
						}
					})
				})
				this.formConfig = formConfigItem
				this.dialogShow = true
				this.dialogTitle =
					"编辑" + JSON.parse(SessionCommon.getCurrentMenuInfo()).title
			},
			viewRow(d) {
				this.type = "look"
				let formConfigItem = this.formConfig
				formConfigItem.map((t) => {
					Object.keys(t).map((res) => {
						if (res == "fieldName") {
							t.filedValue = d.data[t[res]]
						}
					})
				})
				this.formConfig = formConfigItem
				this.dialogShow = true
				this.dialogTitle =
					"查看" + JSON.parse(SessionCommon.getCurrentMenuInfo()).title
			},
			deleteRow(d) {
				const id = d.data.id
				let self = this
				AjaxCommon("XXXX/delete?id=" + id, "delete", {
					optReason: d.optReason,
				}).then((res) => {
					console.log(res, "res...............")
					if (res.data.code == 200) {
						PopupCommon.notify("success", "删除成功")
						this.$refs.userList.refresh()
						self.initPage()
						self.dialogClose()
					} else {
						PopupCommon.notify("error", res.data.message)
					}
				})
			},
			// 左侧选中事件
			handleSelectionChange(d) {
				console.log(d)
				this.leftSelectIds = d
			},
			// 初始化事件
			initPage() {
				let self = this
				AjaxCommon("XXXX/listByPage", "post", {
					// name: this.name,
					// signPrefix: this.signPrefix,
					// pageNo: this.pageNo,
					// pageSize: this.pageSize
				}).then((res) => {
					if (res.data.code == 200) {
						self.dataSource = res.data.result.records
						self.pageCount = res.data.result.total
					} else {
						PopupCommon.notify("error", res.data.message)
					}
				})
			},
		},
		mounted() {
			this.initPage()
		},
	}
</script>

<style></style>
